package com.wj.rpsm.user.mapper;

import com.wj.rpsm.user.pojo.Attention;
import com.wj.rpsm.user.pojo.vo.ForumVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author WeiJin
 * @version 1.0
 */
@Repository
public interface AttentionMapper {

    /**
     * 根据用户id获取关注列表
     * @param id
     * @return
     */
    List<ForumVo> queryAttentionByUserId(@Param("id") Integer id);

    /**
     * 添加关注
     * @param attention
     * @return
     */
   @Insert("insert into attention value (null,#{from_id},#{to_id},#{attend_date},1)")
    Integer addAttention(Attention attention);

    /**
     * 查询是否已关注
     * @param attention
     * @return
     */
    @Select("select * from attention where from_id = #{from_id} and to_id = #{to_id} and isAttend = 1")
    Attention queryIsAttend(Attention attention);

    /**
     * 取消关注
     * @param attention
     * @return
     */
    @Delete("update attention set isAttend = #{isAttend} , attend_date = #{attend_date} " +
            "where attention_id = #{attention_id}")
    Integer cancelAttention(Attention attention);

}
